package com.edocbase.desktop.maildriver;

import com.edocbase.biz.diary.entities.IDiary;
import com.edocbase.biz.diary.entities.MailEntity;
import com.edocbase.diary.job.IJobProgressListener;
import com.edocbase.entity.EntityManager;
import com.edocbase.entity.EntityManagerFactory;
import com.edocbase.webdriver.DriverException;
import com.edocbase.webdriver.IWebAccount;
import com.edocbase.webdriver.mail.MailFile;

public class MailDeleteCommand extends AbstractDriverCommand {
	
	private IDiary diary = null;
	private EntityManager<MailEntity> mailManager = null;
	public MailDeleteCommand(IWebAccount account, IDiary diary) throws DriverException {
		super(account);
		this.diary = diary;
		mailManager = EntityManagerFactory.getEntityManager(MailEntity.class);
	}

	@Override
	public void execute(IJobProgressListener jobListener) throws Exception {
		String uid = diary.getUid();
		MailEntity entity = mailManager.get(uid);
		if (entity != null){
			MailFile file =new MailFile();
			file.setMessageNumber(entity.getMessageNumber());
			file.setUid(entity.getUid());
			driver.delete(file);
			mailManager.delete(uid);
		}
	}

	@Override
	public void stop() {

	}

}
